package chaoyue.study.extend;

/**
 * 关于向上转型
 * 父类型的引用指向子类型的对象
 */
public class ExtendUpcast {
    public static void main(String[] args) {
        Child c = new Child();
        Base b = c;
        // 属性值属于静态绑定
        System.out.println(b.s); // base
        System.out.println(c.s); // child
        System.out.println("---------------");
        // 方法属于动态绑定
        System.out.println(b.getS()); // child
        System.out.println(c.getS()); // child
        System.out.println("---------------");
        b.doSome();
        c.doSome();
    }

    private static class Base {
        public String s = "base";

        public void doSome() {
            System.out.println("base doSome()..." + s);
        }

        public String getS() {
            return s;
        }
    }

    private static class Child extends Base {
        public String s = "child";

        public void doSome() {
            System.out.println("child doSome()..." + s);
        }

        public String getS() {
            return s;
        }
    }
}
